package com.sky.controller.admin;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RequestMapping("/admin/shop")
@RestController("adminShopStatusController")
@Slf4j
public class ShopStatusController {

    private final RedisTemplate<String, Object> redisTemplate;

    @PutMapping("/{status}")
    public Result<?> updateStatus(@PathVariable Integer status){
        redisTemplate.opsForValue().set(ShopStatusConstant.SHOP_STATUS,status);
        return Result.success();
    }

    @GetMapping("/status")
    public Result<?> queryStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(ShopStatusConstant.SHOP_STATUS);
        return Result.success(status == null ? 0 : status);
    }
}
